package com.zzyl.controller.customer;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusResponseBody;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.UserLoginRequestDto;
import com.zzyl.service.DeviceService;
import com.zzyl.service.MemberService;
import com.zzyl.vo.DeviceDataGraphVo;
import com.zzyl.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 用户管理
 */
@Slf4j
@Api(tags = "客户管理")
@RestController
@RequestMapping("/customer/user")
public class CustomerUserController extends BaseController {

    @Autowired
    private MemberService memberService;

    @Autowired
    private DeviceService deviceService;

    /**
     * C端用户登录--微信登录
     *
     * @param userLoginRequestDto 用户登录信息
     * @return 登录结果
     */
    @PostMapping("/login")
    @ApiOperation("登录")
    public ResponseResult<LoginVo> login(@RequestBody UserLoginRequestDto userLoginRequestDto) throws IOException {
        LoginVo login = memberService.login(userLoginRequestDto);
        return success(login);
    }

    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation(value = "查询指定设备的物模型运行状态")
    public ResponseResult queryDevicePropertyStatus(@RequestBody DeviceDto deviceDto) {
        QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData data =
                deviceService.queryDevicePropertyStatus(deviceDto);
        return ResponseResult.success(data);
    }

    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation(value = "按天统计查询指标数据")
    public ResponseResult<List<DeviceDataGraphVo>> queryDeviceDataListByDay(String iotId,Long endTime,String functionId,Long startTime) {
        List<DeviceDataGraphVo> list =deviceService.queryDeviceDataListByDay(iotId,endTime,functionId,startTime);
        return ResponseResult.success(list);
    }

    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation(value = "按周统计查询指标数据")
    public ResponseResult<List<DeviceDataGraphVo>> queryDeviceDataListByWeek(String iotId,Long endTime,String functionId,Long startTime) {
        List<DeviceDataGraphVo> list =deviceService.queryDeviceDataListByWeek(iotId,endTime,functionId,startTime);
        return ResponseResult.success(list);
    }

}
